//
//  SimpleTableViewController.m
//  SimpleTable
//
//  Created by Simon on 1/12/13.
//  Copyright (c) 2013 Appcoda. All rights reserved.
//

#import "SimpleTableViewController.h"
#import "CommonDB.h"
#import "Scores.h"

@interface SimpleTableViewController ()

@end

@implementation SimpleTableViewController
{
    //NSArray *recipes;
    NSMutableArray*_scores;
}
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewDidAppear:(BOOL)animated {
    
    /*scores = [NSMutableArray arrayWithCapacity:20];
    Scores *s = [[Scores alloc] init];
    s.namePlayer = @"Bill Evans";
    s.score = 50;
    [scores addObject:s];
    
    s = [[Scores alloc] init];
    s.namePlayer = @"Bill";
    s.score = 100;
    [scores addObject:s];
    
    s = [[Scores alloc] init];
    s.namePlayer = @"Evans";
    s.score = 200;
    [scores addObject:s];*/
    
    //[[CommonDB shared] open];
    //self.scores = [[CommonDB shared] getAllScores];
    //[[CommonDB shared] close];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _scores = [NSMutableArray arrayWithCapacity:20];
    Scores *s = [[Scores alloc] init];
    s.namePlayer = @"Bill Evans";
    s.score = 50;
    [_scores addObject:s];
    
    s = [[Scores alloc] init];
    s.namePlayer = @"Bill";
    s.score = 100;
    [_scores addObject:s];
    
    s = [[Scores alloc] init];
    s.namePlayer = @"Evans";
    s.score = 200;
    [_scores addObject:s];


    // Initialize table data
    //recipes = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_scores count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }
    
    Scores*s = (_scores)[indexPath.row];
    
    UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
    nameLabel.text = s.namePlayer;
    
    UILabel *gameLabel = (UILabel *)[cell viewWithTag:101];
    gameLabel.text = [NSString stringWithFormat:@"%d",s.score];
    
    UIImageView *ratingImageView = (UIImageView *)[cell viewWithTag:102];
    
    if(indexPath.row == 0)
    {
        ratingImageView.image = [UIImage imageNamed:@"cup_gold.png"];
    }
    else if(indexPath.row == 1)
    {
        ratingImageView.image = [UIImage imageNamed:@"cup_silver.png"];
    }
    else if(indexPath.row == 2)
    {
        ratingImageView.image = [UIImage imageNamed:@"cup_bronze.png"];
    }
    else
    {
        ratingImageView.image = [UIImage imageNamed:@"ic_launcher.png"];
    }
    
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
@end
